﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class FullClassDefinitionElement : ClassDefinitionElement
    {
        protected TokenInfo type;
        protected List<IdElement> parents;
        protected List<ISectionElement> sections;

        public TokenInfo Type { get { return type; } set { type = value; } }
        public List<IdElement> Parents { get { return parents; } set { parents = value; } }
        public List<ISectionElement> Sections { get { return sections; } set { sections = value; } }

        public FullClassDefinitionElement(TokenInfo StartInfo, TokenInfo Type, List<IdElement> Parents, List<ISectionElement> Sections, List<TokenInfo> Comments)
            : base(StartInfo, Comments)
        {
            type = Type;
            parents = Parents;
            sections = Sections;
        }

        public override string ToString()
        {
            string result = "class";
            if (type != null) result += string.Format(" {0}", type);
            if ((parents != null) && (parents.Count > 0)) result += string.Format(" ({0})", parents.Join(", "));
            return ((sections != null) && (sections.Count > 0)) ? string.Format("{0}\r\n{1}\r\nend", result, sections.Join("\r\n")) : result;
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            if (parents != null)
                foreach (IdElement parent in parents)
                    yield return parent;
            if (sections != null)
                foreach (ISectionElement section in sections)
                    yield return section;
        }
    }
}
